<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>添加仓库</title>
    <script type="text/javascript">
      Ext.onReady(function(){
        var number = new Ext.form.NumberField({
          fieldLabel: '编号',
          allowBlank: false,
          blankText: "编号不能为空",
          name: 'number',
          anchor: '95%'
        });

        var name = new Ext.form.TextField({
          fieldLabel: '名称',
          allowBlank: false,
          blankText: "仓库名称不能为空",
          name: 'name',
          anchor: '95%'
        });

        var warehouseTypeTemplate = new Ext.XTemplate('<tpl for="."><div class="search-item">', '{name}', '</div></tpl>');
        warehouseTypeTemplate.compile();
        var warehouseTypeStore = new Ext.data.Store({
          proxy: new Ext.data.HttpProxy({
            url: "/warehouse_type/getAllWarehouseTypes?for_cbb=true"
          }),
          reader: new Ext.data.JsonReader({
            totalProperty: 'totalProperty',
            root: 'root'
          }, [{
              name: 'id'
            },{
              name: 'name'
            }])
        });

        var warehouseType = new Ext.form.ComboBox({
          fieldLabel: '类型',
          store: warehouseTypeStore,
          allowBlank: false,
          typeAhead: true,
          triggerAction: 'all',
          selectOnFocus:true,
          valueField: 'id',
          displayField: 'name',
          hiddenName: 'warehouse_type_id',
          emptyText:'选择仓库类型...',
          //allowBlank: false,
          anchor: '95%'
        });

        var desc = new Ext.form.TextArea({
          fieldLabel: '描述',
          name: 'description',
          height:80,
          anchor: '95%'
        });
        
        var newWarehouseForm = new Ext.FormPanel({
          labelWidth: 75, // label settings here cascade unless overridden
          url:'/warehouse/create',
          frame:true,
          //title: '添加仓库',
          bodyStyle:'padding:5px 5px 0',
          labelAlign: 'right',
          width: 290,
          height:205,
          items: [number,name,warehouseType,desc],
          buttons: [{
              text: '提交',
              iconCls: 'icon-save',
              handler: function(){
                // check form value
                if (newWarehouseForm.form.isValid()) {
                  newWarehouseForm.form.submit({
                    method: 'GET',
                    success: function(result, response){
                      if (response.result.info == "成功") {
                        //添加成功后，隐藏窗口，并刷新Grid
                        newWarehouseWin.destroy();
                      }
                      else {
                        Ext.MessageBox.alert('消息', response.result.info);
                      }
                    },
                    failure: function(result, response){
                      Ext.MessageBox.alert('提示', result.responseText);
                    }
                  });
                }
                else {
                  Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                }
              }
            },{
              text: '关闭',
              iconCls: 'exit',
              handler: function(){
                newWarehouseForm.getForm().reset();
                newWarehouseWin.destroy();
              }
            }]
        });
        newWarehouseForm.render('new_warehouse_form');
      })
    </script>
  </head>
  <body>
    <div id="new_warehouse_form"></div>
  </body>
</html>
